package entities;

import java.io.Serializable;

import javax.persistence.*;

import ejb.dto.HotelDTO;

import java.util.List;


/**
 * The persistent class for the hotels database table.
 * 
 */
@Entity
@Table(name="hotels", uniqueConstraints=@UniqueConstraint(columnNames={"NAME", "LOCATION_ID"}))
@NamedQueries({
	@NamedQuery(name="Hotel.findAll", query="SELECT h FROM Hotel h"),
	@NamedQuery(name="Hotel.findByLocation", query="SELECT h FROM Hotel h WHERE h.location=:l")
})
public class Hotel implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;

	private String address;

	private String description;

	@ManyToOne
	private Location location;

	private String name;

	/**
	 * bi-directional many-to-one association to HotelAvailability
	 */
	@OneToMany(mappedBy="hotel")
	private List<HotelAvailability> hotelAvailabilities;

	/**
	 * bi-directional many-to-many association to Package
	 */
	@ManyToMany(mappedBy="hotels")
	private List<Package> packages;
	

	//CONSTRUCTORS
	public Hotel() {
	}
	
	public Hotel(HotelDTO hotel, Location location){
		this.id = hotel.getId();
		this.address = hotel.getAddress();
		this.description = hotel.getDescription();
		this.name = hotel.getName();
		this.location = location;
	}
	
	
	
	//GETTER AND SETTER
	public Location getLocation() {
		return location;
	}

	public void setLocation(Location location) {
		this.location = location;
	}


	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getAddress() {
		return this.address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<HotelAvailability> getHotelAvailabilities() {
		return this.hotelAvailabilities;
	}

	public void setHotelAvailabilities(List<HotelAvailability> hotelAvailabilities) {
		this.hotelAvailabilities = hotelAvailabilities;
	}
	
	public List<Package> getPackages() {
		return packages;
	}

	public void setPackages(List<Package> packages) {
		this.packages = packages;
	}
	
	//METHODS
	
	/**
	 * add HotelAvailability to list
	 * @param hotelAvailability
	 * @return list of HotelAvailability
	 */
	public HotelAvailability addHotelAvailability(HotelAvailability hotelAvailability) {
		getHotelAvailabilities().add(hotelAvailability);
		hotelAvailability.setHotel(this);

		return hotelAvailability;
	}

	/**
	 * remove HotelAvailability from list
	 * @param hotelAvailability
	 * @return list of HotelAvailability
	 */
	public HotelAvailability removeHotelAvailability(HotelAvailability hotelAvailability) {
		getHotelAvailabilities().remove(hotelAvailability);
		hotelAvailability.setHotel(null);

		return hotelAvailability;
	}

}